package com.example.mall.web.controller;

import com.example.mall.domain.TransactionAlerts;
import com.example.mall.dto.TransactionAlertsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.TransactionAlertsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ITransactionAlertsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/transactionAlerts")
public class TransactionAlertsController {

    @Autowired
    public ITransactionAlertsService transactionAlertsService;

    /**
     * 分页查询异常交易报警表信息
     * @param transactionAlertsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询异常交易报警表信息",notes = "分页查询异常交易报警表信息",httpMethod = "GET")
    public JSONResult queryPage(TransactionAlertsQuery transactionAlertsQuery){
        PageDTO<TransactionAlertsDto> transactionAlertsDtoPageDTO = transactionAlertsService.queryPage(transactionAlertsQuery);
        return JSONResult.success("查询成功",transactionAlertsDtoPageDTO);
    }

    /**
     * 根据id查询异常交易报警表信息
     * @param id
     * @return
     */
    @GetMapping("query/{id}")
    @ApiOperation(value = "根据id查询异常交易报警表信息",notes = "根据id查询异常交易报警表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.TRANSACTION_ALERTID_NOT_ID);
        }
        TransactionAlerts transactionAlerts = transactionAlertsService.getById(id);
        return JSONResult.success("查询成功",transactionAlerts);
    }

    /**
     * 根据id查询异常交易报警表信息
     * @param id
     * @return
     */
    @GetMapping("queryTransactionAlertsById/{id}")
    @ApiOperation(value = "根据id查询异常交易报警表信息",notes = "根据id查询异常交易报警表信息",httpMethod = "GET")
    public JSONResult queryTransactionAlertsById(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.TRANSACTION_ALERTID_NOT_ID);
        }
        TransactionAlerts transactionAlerts = transactionAlertsService.queryTransactionAlertsById(id);
        return JSONResult.success("查询成功",transactionAlerts);
    }

    /**
     * 查询全部异常交易报警表信息
     * @param
     * @return
     */
    @GetMapping("queryTransactionAlertsList")
    @ApiOperation(value = "查询全部异常交易报警表信息",notes = "查询全部异常交易报警表信息",httpMethod = "GET")
    public JSONResult queryTransactionAlertsList(){
        List<TransactionAlerts> transactionAlerts = transactionAlertsService.queryTransactionAlertsList();
        return JSONResult.success("查询成功",transactionAlerts);
    }

    /**
     * 新增异常交易报警表
     * @param transactionAlertsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增异常交易报警表",notes = "新增异常交易报警表",httpMethod = "POST")
    public JSONResult insert(@RequestBody TransactionAlertsDto transactionAlertsDto){
        transactionAlertsService.insert(transactionAlertsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改异常交易报警表信息
     * @param transactionAlertsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改异常交易报警表信息",notes = "修改异常交易报警表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody TransactionAlertsDto transactionAlertsDto){
        transactionAlertsService.update(transactionAlertsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除异常交易报警表信息
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除异常交易报警表信息",notes = "删除异常交易报警表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activitiesProductId") Long id) {
        transactionAlertsService.delete(id);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除异常交易报警表信息
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除异常交易报警表信息",notes = "批量删除异常交易报警表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ids) {
        transactionAlertsService.deleteBatch(ids);
        return JSONResult.success("批量删除成功");
    }
}
